<!DOCTYPE html>
<html lang="zh-cmn-Hans">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,viewport-fit=cover">
    <title>分析设备</title>
    <link rel="stylesheet" href="/static/css/weui.css" />
    <link rel="stylesheet" href="/static/css/example.css" />
</head>

<body ontouchstart>
    <div class="container" id="container"></div>
    <script type="text/html" id="tpl_home">
            <script src="/static/js/jquery.min.js"></script>
            <script src="/static/js/weui.min.js"></script>
            <script type="text/javascript" src="/static/js/jweixin-1.4.0.js"></script>         
            <script src="/static/js/zepto.min.js"></script>
            <script src="/static/js/example.js"></script>
            <!-- <script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>-->  
            
            
            <script type="text/javascript">
                $(function() {

                    function getQueryString(name) {
                        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
                        var r = decodeURI(window.location.search).substr(1).match(reg);
                        if (r != null) return (r[2]);
                        return null;
                    };

                    $(document).ready(function() {
                        var deviceid = getQueryString('deviceid');
                        var code = getQueryString('code');
                        // 根据deviceid和code 获取设备情况
                        $.ajax({
                            url: 'http://gzh.zjnnhj.com/niuneng/getDeviceInfo',
                            type: "post",
                            data: JSON.stringify({
                                "code": code,
                                "deviceid": deviceid
                            }),
                            dataType: "json",
                            success: function(res) {
                                res =JSON.parse(res)
                                // 成功获取时跳转操作页面
                                if (res.errcode == 0){
                                    // 获取结果，传递到下一个界面
                                    // 设备id， 社区名称， 社区地址， 已使用容积， 最大容积， 设备状态， 小区编号
                                    var deviceData = res.deviceInfo;
                                    var carbinId = deviceData.deviceid;
                                    var commuName = deviceData.name ? deviceData.name : '金帝海铂雅苑';
                                    var commuAdd = deviceData.address ? deviceData.address : '杭州余杭区振兴西路158号';
                                    var usedVol = '正常';//deviceData.volume;
                                    var maxVol = '5立方';//deviceData.maxvolume;
                                    var status = '设备正常';//deviceData.exception;
                                    var area = deviceData.area;


                                    var fredirect_uri = 'http://gzh.zjnnhj.com/niuneng/toCerti.html?carbinId=' + carbinId + '&commuName=' + commuName + '&commuAdd=' + commuAdd + '&usedVol=' + usedVol + '&maxVol=' + maxVol + '&status=' + status + '&area=' + area;
                                    var ffurl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx5f2850581e4e064d&redirect_uri=" + encodeURIComponent(fredirect_uri) + "&response_type=code&scope=snsapi_base&state=123#wechat_redirect";
                                    location.href = ffurl;
                                } else{
                                    alert(res.errmsg)
                                    // 失败时退出页面
                                    setTimeout(function() {
                                        //这个可以关闭安卓系统的手机
                                        document.addEventListener(
                                            "WeixinJSBridgeReady",
                                            function() {
                                                WeixinJSBridge.call("closeWindow");
                                            },
                                            false
                                        );
                                            //这个可以关闭ios系统的手机
                                        WeixinJSBridge.call("closeWindow");
                                        }, 500);

                                }
                        }            
                    })
                })
            })

            </script>

    </script>
</body>

</html>